#include <iostream>
#include <vector>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> psz;
    for (int i = 0; i < N; i++)
    {
        int sz;
        std::cin >> sz;
        psz.push_back(sz);
    }

    int pgn = 1474560 / 512;
    std::vector<int> dp(pgn + 1, 0);

    for (int i = 0; i < N; i++)
    {
        int pgz_n = (psz[i] + 511) / 512;
        for (int j = pgn; j >= pgz_n; j--)
        {
            dp[j] = std::max(dp[j], dp[j - pgz_n] + psz[i]);
        }
    }

    std::cout << dp[pgn] << std::endl;

    return 0;
}